<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <template id="pengfan">
      您的问题： <input type="text" v-model="question" />
      <!-- <button @click="queryAnswer">查找答案</button> -->
    </template>
    <script src="../js/vue.js"></script>
    <script>
      Vue.createApp({
        template: "#pengfan",
        data() {
          return {
            // 侦听question的变化时，去进行一些逻辑的处理（javascript，网络请求）
            question: "Hello World",
            answer: "",
          };
        },
        watch: {
          //question侦听的data中的属性的名称
          // newValue变化后的值
          // oldValue变化前的旧值
          question: function (newValue, oldValue) {
            console.log("新值：", newValue, "旧值：", oldValue);
            this.queryAnswer();
          },
        },
        methods: {
          queryAnswer() {
            console.log(`你的问题${this.question}的答案是哈哈哈哈哈`);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
